home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / cleandialog.py < prev    next >
Text File  |  2009-10-09  |  10KB  |  347 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2008 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Authors: Don Welch
  20. #
  21.  
  22. # StdLib
  23. import operator
  24.  
  25. # Local
  26. from base.g import *
  27. from base import device, utils, maint
  28. from prnt import cups
  29. from base.codes import *
  30. from ui_utils import *
  31.  
  32. # Qt
  33. from PyQt4.QtCore import *
  34. from PyQt4.QtGui import *
  35.  
  36. # Ui
  37. from cleandialog_base import Ui_Dialog
  38.  
  39.  
  40. CLEAN_TYPE_INITIAL = 1000
  41. CLEAN_TYPE_TEST = 1001
  42.  
  43. PAGE_START = 0
  44. PAGE_LEVEL_1 = 1
  45. PAGE_LEVEL_2 = 2
  46. PAGE_LEVEL_3 = 3
  47. PAGE_FRONT_PANEL = 4
  48.  
  49. BUTTON_CLEAN = 0
  50. BUTTON_NEXT = 1
  51. BUTTON_FINISH = 2
  52.  
  53.  
  54. #d = None
  55. def true():
  56.     return True
  57.  
  58.  
  59.  
  60. class CleanDialog(QDialog, Ui_Dialog):
  61.     def __init__(self, parent, device_uri):
  62.         QDialog.__init__(self, parent)
  63.         self.setupUi(self)
  64.         self.device_uri = device_uri
  65.         self.clean_type = CLEAN_TYPE_INITIAL
  66.         self.abort = False
  67.         self.seq_index = 0
  68.         self.step = 1
  69.         self.step_max = 0
  70.  
  71.         self.max_steps = {
  72.                       CLEAN_TYPE_UNSUPPORTED : 1,
  73.                       CLEAN_TYPE_PCL : 4,
  74.                       CLEAN_TYPE_LIDIL : 4,
  75.                       CLEAN_TYPE_PCL_WITH_PRINTOUT : 4,
  76.                     }
  77.  
  78.         self.seq = { # (func|method, tuple of params|None)
  79.                     CLEAN_TYPE_INITIAL: [ # (used when starting up and clean-type isn't known)
  80.                                (self.showStartPage, None),
  81.                                (self.endStartPage, None), # switch to a valid clean-type here
  82.                             ],
  83.  
  84.                     CLEAN_TYPE_UNSUPPORTED : [
  85.                                 (self.showFrontPanelPage, None),
  86.                                 (self.endFrontPanelPage, None),
  87.                                 (self.close, None),
  88.                             ],
  89.  
  90.                     CLEAN_TYPE_PCL : [ # 1
  91.                             (self.showLevel1Page, None),
  92.                             (self.endLevel1Page, None),
  93.                             (self.doClean, (1,)),
  94.                             (self.showLevel2Page, None),
  95.                             (self.endLevel2Page, None),
  96.                             (self.doClean, (2,)),
  97.                             (self.showLevel3Page, None),
  98.                             (self.endLevel3Page, None),
  99.                             (self.doClean, (3,)),
  100.                             (self.close, None),
  101.                             ],
  102.  
  103.                     CLEAN_TYPE_LIDIL : [  # 2
  104.                             (self.showLevel1Page, None),
  105.                             (self.endLevel1Page, None),
  106.                             (self.doClean, (1,)),
  107.                             (self.showLevel2Page, None),
  108.                             (self.endLevel2Page, None),
  109.                             (self.doClean, (2,)),
  110.                             (self.showLevel3Page, None),
  111.                             (self.endLevel3Page, None),
  112.                             (self.doClean, (3,)),
  113.                             (self.close, None),
  114.                             ],
  115.  
  116.                     CLEAN_TYPE_PCL_WITH_PRINTOUT : [ # 3
  117.                             (self.showLevel1Page, None),
  118.                             (self.endLevel1Page, None),
  119.                             (self.doClean, (1,)),
  120.                             (self.showLevel2Page, None),
  121.                             (self.endLevel2Page, None),
  122.                             (self.doClean, (2,)),
  123.                             (self.showLevel3Page, None),
  124.                             (self.endLevel3Page, None),
  125.                             (self.doClean, (3,)),
  126.                             # TODO: Add print-out
  127.                             (self.close, None),
  128.                             ],
  129.                     }
  130.  
  131.  
  132.         self.initUi()
  133.         QTimer.singleShot(0, self.nextSequence)
  134.  
  135.  
  136.     def initUi(self):
  137.         # connect signals/slots
  138.         self.connect(self.CancelButton, SIGNAL("clicked()"), self.CancelButton_clicked)
  139.         self.connect(self.NextButton, SIGNAL("clicked()"), self.NextButton_clicked)
  140.         self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_noDevices"), self.DeviceUriComboBox_noDevices)
  141.         self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_currentChanged"), self.DeviceUriComboBox_currentChanged)
  142.         self.DeviceComboBox.setFilter({'clean-type': (operator.gt, 0)})
  143.  
  144.         if self.device_uri:
  145.             self.DeviceComboBox.setInitialDevice(self.device_uri)
  146.  
  147.         # Application icon
  148.         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
  149.  
  150.  
  151.     def NextButton_clicked(self):
  152.         self.nextSequence()
  153.  
  154.  
  155.     def nextSequence(self):
  156.         while True:
  157.             try:
  158.                 seq, params = self.seq[self.clean_type][self.seq_index]
  159.             except IndexError:
  160.                 break
  161.  
  162.             if seq is None:
  163.                 self.seq_index += 1
  164.                 continue
  165.  
  166.             self.new_page = False
  167.  
  168.             t = []
  169.             if params is not None:
  170.                 for p in params:
  171.                     try:
  172.                         t.append(p())
  173.                     except:
  174.                         t.append(p)
  175.  
  176.             try:
  177.                 log.debug("%s(%s)" % (seq.func_name, ','.join([repr(x) for x in t])))
  178.             except AttributeError:
  179.                 pass
  180.  
  181.             try:
  182.                 seq(*t)
  183.             except Error:
  184.                 CheckDeviceUI(self)
  185.                 break
  186.  
  187.             self.seq_index += 1
  188.  
  189.             if self.new_page:
  190.                 break
  191.  
  192.             if self.abort:
  193.                 self.close()
  194.  
  195.  
  196.     def showStartPage(self):
  197.         self.setCleanButton(BUTTON_NEXT)
  198.         num_devices = self.DeviceComboBox.setDevices()
  199.  
  200.         if num_devices == 1:
  201.             self.skipPage()
  202.             return
  203.  
  204.         self.DeviceComboBox.updateUi()
  205.         self.displayPage(PAGE_START)
  206.  
  207.  
  208.     def endStartPage(self):
  209.         self.mq = device.queryModelByURI(self.device_uri)
  210.         self.clean_type = self.mq.get('clean-type', CLEAN_TYPE_NONE)
  211.         self.seq_index = -1
  212.  
  213.         log.debug("clean-type=%d" % self.clean_type)
  214.         self.step_max = self.max_steps[self.clean_type]
  215.  
  216.         try:
  217.             self.dev = device.Device(self.device_uri)
  218.         except Error:
  219.             CheckDeviceUI(self)
  220.             return
  221.  
  222.  
  223.     def showLevel1Page(self):
  224.         self.setCleanButton(BUTTON_CLEAN)
  225.         self.displayPage(PAGE_LEVEL_1)
  226.  
  227.  
  228.     def endLevel1Page(self):
  229.         pass
  230.  
  231.  
  232.     def showLevel2Page(self):
  233.         self.displayPage(PAGE_LEVEL_2)
  234.  
  235.  
  236.     def endLevel2Page(self):
  237.         pass
  238.  
  239.  
  240.     def showLevel3Page(self):
  241.         self.displayPage(PAGE_LEVEL_3)
  242.  
  243.  
  244.     def endLevel3Page(self):
  245.         pass
  246.  
  247.  
  248.     def showFrontPanelPage(self):
  249.         self.setCleanButton(BUTTON_FINISH)
  250.         self.displayPage(PAGE_FRONT_PANEL)
  251.  
  252.  
  253.     def endFrontPanelPage(self):
  254.         pass
  255.  
  256.  
  257.     def DeviceUriComboBox_currentChanged(self, device_uri):
  258.         self.device_uri = device_uri
  259.  
  260.  
  261.     def DeviceUriComboBox_noDevices(self):
  262.         FailureUI(self, self.__tr("<b>No devices that support print cartridge cleaning found.</b><p>Click <i>OK</i> to exit.</p>"))
  263.         self.close()
  264.  
  265.  
  266.     def CancelButton_clicked(self):
  267.         self.close()
  268.  
  269.  
  270.     def doClean(self, level):
  271.         try:
  272.             try:
  273.                 self.dev.open()
  274.             except Error:
  275.                 CheckDeviceUI(self)
  276.             else:
  277.                 if self.dev.isIdleAndNoError():
  278.                     if self.clean_type in (CLEAN_TYPE_PCL, # 1
  279.                                       CLEAN_TYPE_PCL_WITH_PRINTOUT): # 3
  280.  
  281.                         if level == 1:
  282.                             maint.cleanType1(self.dev)
  283.  
  284.                         elif level == 2:
  285.                             maint.primeType1(self.dev)
  286.  
  287.                         else: # 3
  288.                             maint.wipeAndSpitType1(self.dev)
  289.  
  290.  
  291.                     elif self.clean_type == CLEAN_TYPE_LIDIL: # 2
  292.                         if level == 1:
  293.                             maint.cleanType2(self.dev)
  294.  
  295.                         elif level == 2:
  296.                             maint.primeType2(self.dev)
  297.  
  298.                         else: # 3
  299.                             maint.wipeAndSpitType2(self.dev)
  300.  
  301.                     maint.print_clean_test_page(self.dev)
  302.  
  303.                 else:
  304.                     CheckDeviceUI(self)
  305.  
  306.         finally:
  307.             if self.dev is not None:
  308.                 self.dev.close()
  309.  
  310.  
  311.     #
  312.     # Misc
  313.     #
  314.  
  315.     def displayPage(self, page):
  316.         self.updateStepText(self.step)
  317.         self.step += 1
  318.         self.new_page = True
  319.         self.StackedWidget.setCurrentIndex(page)
  320.  
  321.  
  322.     def skipPage(self):
  323.         self.step += 1
  324.         self.new_page = False
  325.  
  326.  
  327.     def updateStepText(self, p=None):
  328.         if p is None or not self.step_max:
  329.             self.StepText.setText(QString(""))
  330.         else:
  331.             self.StepText.setText(self.__tr("Step %1 of %2").arg(p).arg(self.step_max))
  332.  
  333.  
  334.     def setCleanButton(self, typ=BUTTON_CLEAN):
  335.         if typ == BUTTON_CLEAN:
  336.             self.NextButton.setText(self.__tr("Clean"))
  337.         elif typ == BUTTON_NEXT:
  338.             self.NextButton.setText(self.__tr("Next >"))
  339.         elif typ == BUTTON_FINISH:
  340.             self.NextButton.setText(self.__tr("Finish"))
  341.  
  342.  
  343.     def __tr(self,s,c = None):
  344.         return qApp.translate("CleanDialog",s,c)
  345.  
  346.  
  347.